$(function () {
    // 地图
    showTimeCharts()
    // 本年度新增市场主体趋势
    var data = {
        data: [
            [
                2,
                1,
                3,
                0,
                0,
                1,
                2,
                1,
                13,
                3,
                1,
                1
            ],
            [
                2,
                1,
                3,
                0,
                0,
                1,
                2,
                1,
                13,
                3,
                1,
                1
            ],
            [
                2,
                1,
                3,
                0,
                0,
                1,
                2,
                1,
                13,
                3,
                1,
                1
            ],
            [
                2,
                1,
                3,
                0,
                0,
                1,
                2,
                1,
                13,
                3,
                1,
                1
            ],
            [
                10,
                7,
                13,
                12,
                9,
                2,
                3,
                14,
                30,
                18,
                8,
                23
            ]
        ]
    }
    showBarRight(data)

    showRightPie1()

    showRightPie2()

    //
    showRightBar1()

    showBar3()

})

// 地图
function showTimeCharts() {
    $.ajax({
        url: './aks.json',
        success: function (json) {
            echarts.registerMap('aks', json);
            var myChart = echarts.init(document.getElementById('map'))
            var data = [{
                'time': 2017,
                'data': [{
                    'name': '拜城县',
                    'value': [10211, 31.222, '拜城县']
                }, {
                    'name': '库车县',
                    'value': [43312, 13.202, '库车县']
                }, {
                    'name': '沙雅县',
                    'value': [20971, 6.369, '沙雅县']
                }, {
                    'name': '阿克苏市',
                    'value': [20867, 6.362, '阿克苏市']
                }, {
                    'name': '阿瓦提县',
                    'value': [14682, 4.477, '阿瓦提县']
                }, {
                    'name': '柯坪县',
                    'value': [12970, 3.807, '柯坪县']
                }, {
                    'name': '乌什县',
                    'value': [10960, 3.328, '乌什县']
                }, {
                    'name': '温宿县',
                    'value': [9156, 2.787, '温宿县']
                }, {
                    'name': '新和县',
                    'value': [8633, 2.629, '新和县']
                }],
                barData: [{
                        name: '药品生产',
                        data: [1, 2, 3, 4, 5, 6, 7, 8, 9]
                    },
                    {
                        name: '药品经营',
                        data: [12, 22, 23, 24, 52, 6, 7, 8, 9]
                    },
                    {
                        name: '医疗器械生产',
                        data: [12, 22, 3, 4, 5, 6, 7, 8, 9]
                    },
                    {
                        name: '医疗器械经营',
                        data: [12, 22, 3, 4, 5, 6, 7, 8, 9]
                    }
                ]
            }]

            var option = {
                // backgroundColor: '#25499F',
                baseOption: {
                    animationDurationUpdate: 1000,
                    animationEasingUpdate: 'quinticInOut',
                    timeline: {
                        show: false,
                        axisType: 'category',
                        orient: 'vertical',
                        autoPlay: false,
                        inverse: true,
                        playInterval: 4000,
                        // symbol: "rect",
                        left: null,
                        right: 5,
                        top: 20,
                        bottom: 20,
                        width: 46,
                        height: null,
                        label: {
                            normal: {
                                position: 'left',
                                textStyle: {
                                    color: '#4BCEEC',
                                    fontSize: 14,

                                }
                            },
                            emphasis: {
                                textStyle: {
                                    color: '#97B8C9',
                                    fontSize: 18,
                                }
                            }
                        },
                        symbol: 'none',
                        lineStyle: {
                            width: 1,
                            color: '#4BCEEC',
                            type: 'dotted'
                        },
                        checkpointStyle: {
                            symbolSize: 20,
                            symbol: 'image://./img/checkpoint-style-icon.png'
                        },


                        controlStyle: {
                            showNextBtn: false,
                            showPrevBtn: false,
                            normal: {
                                color: '#666',
                                borderColor: '#666',
                                fontSize: 18
                            },
                            emphasis: {
                                color: '#aaa',
                                borderColor: '#aaa',
                                fontSize: 18,
                            }
                        },
                        data: data.map(function (ele) {
                            return ele.time
                        })
                    },

                    tooltip: {
                        formatter: function (params) {
                            if (params.componentSubType == 'bar') {
                                return params.value
                            }
                            if ('value' in params.data) {
                                return params.data.value[2] + ': ' + params.data.value[0]
                            }
                        }
                    },
                    grid: {
                        left: '90',
                        right: '42%',
                        top: '70%',
                        bottom: 50
                    },
                    legend: {
                        data: ['药品生产', '药品经营', '医疗器械生产', '医疗器械经营'],
                        textStyle: {
                            color: '#fff',
                            fontSize: 18
                        },
                        orient: 'vertical',
                        right: 142,
                        bottom: 108
                    },
                    xAxis: {},
                    yAxis: {},
                    series: [{
                            id: 'map',
                            type: 'map',
                            mapType: 'aks',
                            top: '30',
                            bottom: '38%',
                            left: '13%',
                            right: '40%',
                            showLegendSymbol: true,
                            itemStyle: {
                                normal: {
                                    label: {
                                        show: true,
                                        fontSize: 18,
                                        textStyle: {
                                            fontSize: 18
                                        },
                                    },
                                    textStyle: {
                                        fontSize: 18
                                    },
                                    show: true,
                                    areaColor: '#323c48',
                                    borderColor: '#fff'
                                },
                                emphasis: {
                                    label: {
                                        show: true,
                                        fontSize: 18,
                                        textStyle: {
                                            fontSize: 18
                                        },
                                    },
                                    textStyle: {
                                        fontSize: 18
                                    },
                                    areaColor: 'rgba(50,197,255, 0.5)'
                                }
                            },

                            data: []
                        },
                        {
                            id: 'pie1',
                            type: 'pie',
                            radius: [
                                '12%', '23%'
                            ],
                            center: [
                                '78%', '35%'
                            ],
                            //roseType: 'area',
                            tooltip: {
                                formatter: '{b} {d}%'
                            },
                            // minAngle: 20,

                            data: [],
                            label: {
                                normal: {
                                    formatter: '{b} \n {d}%',

                                    textStyle: {
                                        color: '#97B8C9',
                                        fontSize: 18
                                    }
                                }
                            },
                            labelLine: {
                                normal: {
                                    lineStyle: {
                                        color: '#ddd',
                                        fontSize: 18
                                    }
                                }
                            },
                            itemStyle: {
                                normal: {
                                    borderColor: 'rgba(0,0,0,0.3)',
                                    borderSize: 1,
                                    fontSize: 18
                                }
                            }
                        },
                        {
                            id: 'bar',
                            type: 'bar',
                            tooltip: {
                                show: false
                            },
                            barWidth: 16,
                            itemStyle: {
                                normal: {
                                    color: '#EB3432'
                                }
                            },
                            label: {
                                normal: {
                                    show: true,
                                    textStyle: {
                                        color: '#fff',
                                        fontSize: 18
                                    }
                                }
                            },
                            data: []
                        },
                        {
                            id: 'bar2',
                            type: 'bar',
                            itemStyle: {
                                normal: {
                                    color: '#FF7E22'
                                }
                            },
                            tooltip: {
                                show: false
                            },

                            label: {
                                normal: {
                                    show: true,
                                    textStyle: {
                                        color: '#fff',
                                        fontSize: 18
                                    }
                                }
                            },
                            data: []
                        },
                        {
                            id: 'bar3',
                            type: 'bar',
                            itemStyle: {
                                normal: {
                                    color: '#32C5FF'
                                }
                            },
                            tooltip: {
                                show: false
                            },

                            label: {
                                normal: {
                                    show: true,
                                    textStyle: {
                                        color: '#fff',
                                        fontSize: 18
                                    }
                                }
                            },
                            data: []
                        },
                        {
                            id: 'bar4',
                            type: 'bar',
                            itemStyle: {
                                normal: {
                                    color: '#DA55FF'
                                }
                            },
                            tooltip: {
                                show: false
                            },

                            label: {
                                normal: {
                                    show: true,
                                    textStyle: {
                                        color: '#fff',
                                        fontSize: 18
                                    }
                                }
                            },
                            data: []
                        }

                    ]
                },
                options: []
            }
            for (var i = 0; i < data.length; i++) {
                //计算其余国家GDP
                var restPercent = 100
                var restValue = 0
                var _data_i = data[i].data
                $.each(data[i].data, function (index, ele) {

                    restPercent = restPercent - ele.value[1]
                })

                restValue = data[i].data[0].value[0] * (restPercent / data[i].data[0].value[1])

                option.options.push({
                    visualMap: [{
                        calculable: true,
                        dimension: 0,
                        left: 20,
                        top: 'center',
                        itemWidth: 12,
                        min: data[i].data[8].value[0],
                        max: data[i].data[0].value[0],
                        text: [
                            '高', '低'
                        ],
                        textStyle: {
                            color: '#4BCEEC',
                            fontSize: 18
                        },
                        seriesIndex: [0, 1],
                        inRange: {
                            color: ['#2A53AD', '#3784C6', '#4CCFEC']
                        }
                    }],
                    xAxis: {
                        show: false

                    },
                    yAxis: {
                        type: 'category',
                        axisLabel: {
                            show: true,
                            textStyle: {
                                color: '#ddd',
                                fontSize: 18
                            }
                        },

                        axisTick: {
                            show: false
                        },
                        data: data[i].data.map(function (ele) {
                            return ele.value[2]
                        }).reverse()
                    },
                    series: [{
                            id: 'map',
                            data: data[i].data,
                            top: 100
                        },

                        {
                            id: 'pie1',
                            data: data[i].data.map(function (ele) {
                                return {
                                    name: ele.value[2],
                                    value: ele.value[0]
                                }
                            })
                        }, {
                            id: 'bar',
                            stack: '1',
                            label: {
                                normal: {
                                    position: 'insideRight',
                                    formatter: ' {c}'
                                }
                            },
                            name: data[i].barData[0].name,
                            data: data[i].barData[0].data.map(function (ele) {
                                return ele
                            }).sort(function (a, b) {
                                return a > b
                            })
                        },
                        {
                            id: 'bar2',
                            stack: '1',
                            label: {
                                normal: {
                                    position: 'insideRight',
                                    formatter: ' {c}'
                                }
                            },
                            name: data[i].barData[1].name,
                            data: data[i].barData[1].data.map(function (ele) {
                                return ele
                            }).sort(function (a, b) {
                                return a > b
                            })
                        },
                        {
                            id: 'bar3',
                            stack: '1',
                            label: {
                                normal: {
                                    position: 'insideRight',
                                    formatter: ' {c}'
                                }
                            },
                            name: data[i].barData[2].name,
                            data: data[i].barData[2].data.map(function (ele) {
                                return ele
                            }).sort(function (a, b) {
                                return a > b
                            })
                        },
                        {
                            id: 'bar4',
                            stack: '1',
                            label: {
                                normal: {
                                    position: 'insideRight',
                                    formatter: ' {c}'
                                }
                            },
                            name: data[i].barData[3].name,
                            data: data[i].barData[3].data.map(function (ele) {
                                return ele
                            }).sort(function (a, b) {
                                return a > b
                            })
                        }


                    ]
                })
            }
            myChart.setOption(option)

        }
    })


}


function showBarRight(arrayDa) {
    var myChart = echarts.init(document.getElementById('bar'))
    var option = {
        tooltip: {
            trigger: 'axis',
            textStyle: {
                fontSize: 18
            }
        },
        legend: {
            data: ['药品生产', '药品经营', '医疗器械生产', '医疗器械经营', '增长率'],
            textStyle: {
                color: "#fff",
                fontSize: 18
            },
            top: 20
        },
        grid: {
            top: 80,
            left: 30,
            right: 30,
            bottom: 60,
            containLabel: true
        },
        xAxis: {
            type: 'category',

            // boundaryGap: false,

            axisLine: {
                onZero: false,
                show: true,

                lineStyle: {
                    color: '#1178C9'
                }
            },
            axisLabel: {
                interval: 0,

                textStyle: {
                    color: '#97B8C9',
                    fontSize: 18

                },
                formatter: function (params) {

                    if (params.length > 4) {
                        var _name = params.substring(0, 4) + '\n' + params.substring(4, params.length)
                        return _name
                    }
                    return params
                }

            },

            axisLine: {
                show: true,
                lineStyle: {
                    color: '#07274D'
                }
            },
            axisTick: {
                lineStyle: {
                    color: '#1178C9'
                }
            },
            splitLine: {
                lineStyle: {
                    color: '#07274D'
                }
            },
            data: [
                '1月',
                '1月',
                '1月',
                '1月',
                '1月',
                '1月',
                '1月',
                '1月',
                '1月',
                '1月',
                '1月',
                '1月'


            ]
        },
        yAxis: [

            {
                type: 'value',
                interval: 0,
                splitLine: {
                    lineStyle: {
                        color: '#07274D'
                    }
                },
                axisLine: {
                    onZero: false,

                    lineStyle: {
                        color: '#07274D'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#1178C9'
                    }
                },
                axisLabel: {
                    textStyle: {
                        color: '#97B8C9',
                        fontSize: 18

                    },
                    formatter: '{value} '
                }
            },
            {
                type: 'value',
                name: '',
                min: 0,
                max: 100,
                splitNumber: 5,
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: '#07274D'
                    }
                },
                axisLine: {
                    onZero: false,

                    lineStyle: {
                        color: '#07274D'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#1178C9'
                    }
                },
                axisLabel: {
                    textStyle: {
                        color: '#97B8C9',
                        fontSize: 16

                    },
                    formatter: '{value}%'
                }
            }
        ],

        series: [{
                name: '药品生产',
                type: 'bar',
                stack: '1',
                itemStyle: {
                    normal: {
                        color: '#EB3432'

                    }
                },
                data: arrayDa.data[0]

            },

            {
                name: '药品经营',
                type: 'bar',
                stack: '1',
                itemStyle: {
                    normal: {
                        color: '#FF7E22'

                    }
                },
                data: arrayDa.data[1]

            },
            {
                name: '医疗器械生产',
                type: 'bar',
                stack: '1',
                itemStyle: {
                    normal: {
                        color: '#32C5FF'

                    }
                },
                data: arrayDa.data[2]

            },
            {
                name: '医疗器械经营',
                type: 'bar',
                stack: '1',
                itemStyle: {
                    normal: {
                        color: '#DA55FF'

                    }
                },
                data: arrayDa.data[3]

            },
            {
                name: '增长率',
                type: 'line',
                yAxisIndex: 1,
                itemStyle: {
                    normal: {
                        color: '#DA55FF'

                    }
                },
                data: arrayDa.data[4]

            }
        ]
    }

    myChart.setOption(option)

}
// 市场主体类型占比

function showRightPie1() {
    var myChart = echarts.init(document.getElementById('pie'))
    var option = {
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b}: {c} ({d}%)',
            textStyle: {
                fontSize: 18
            }
        },
        color: [
            '#EB3432',
            '#F2E52C',
            '#3157EC',
            '#DF31EB',
            '#EB3432',
            '#A5D571',
            '#FF8516',
            '#21FB30',
            '#DF31EB'
        ],
        series: [{
            name: '地区药品许可类型占比',
            type: 'pie',
            radius: [
                '26%', '50%'
            ],
            center: [
                '50%', '50%'
            ],
            // avoidLabelOverlap: false,
            // minAngle: 32,

            label: {
                normal: {
                    formatter: '{b} \n {d}%',
                    show: true,
                    textStyle: {
                        fontSize: 18,
                        color: '#97B8C9'
                    }

                },
                emphasis: {
                    show: true,
                    textStyle: {
                        fontSize: 18,
                        fontWeight: 'bold'
                    }
                }
            },
            labelLine: {
                normal: {
                    show: true
                }
            },
            data: [{
                value: 335,
                name: '药品生产 '
            }, {
                value: 310,
                name: '药品零售 '
            }, {
                value: 234,
                name: '药品批发 '
            }, {
                value: 2135,
                name: '药品连锁'
            }]
        }]
    }

    myChart.setOption(option)


}

function showRightPie2() {
    var myChart = echarts.init(document.getElementById('pie2'))
    var option = {
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b}: {c} ({d}%)',
            textStyle: {
                fontSize: 18
            }
        },
        color: [
            '#10BBFF',
            '#6236FF',
            '#FAE141',
            '#FA6400',
            '#EB3432',
            '#A5D571',
            '#FF8516',
            '#21FB30',
            '#DF31EB'
        ],
        series: [{
            name: '地区器械许可类型占比',
            type: 'pie',
            radius: [
                '26%', '50%'
            ],
            center: [
                '50%', '50%'
            ],
            // avoidLabelOverlap: false,
            // minAngle: 32,

            label: {
                normal: {
                    formatter: '{b} \n {d}%',
                    show: true,
                    textStyle: {
                        fontSize: 18,
                        color: '#97B8C9'
                    }

                },
                emphasis: {
                    show: true,
                    textStyle: {
                        fontSize: 18,
                        fontWeight: 'bold'
                    }
                }
            },
            labelLine: {
                normal: {
                    show: true
                }
            },
            data: [{
                value: 335,
                name: '器械生产 '
            }, {
                value: 310,
                name: '器械批发  '
            }, {
                value: 234,
                name: '器械零售'
            }, {
                value: 2135,
                name: '二类备案'
            }]
        }]
    }

    myChart.setOption(option)


}


function showBar3() {
    var myChart = echarts.init(document.getElementById("bar3"));
    var option = {
        legend: {
            top: '15%',
            data: [
                '药品', '医疗器械'
            ],
            textStyle: {
                color: '#97B8C9',
                fontSize: 16
            }
        },
        tooltip: {
            trigger: 'axis',
            textStyle: {
                fontSize: 16
            }
        },
        grid: {
            top: '28%',

            bottom: '10%',
            containLabel: true
        },
        xAxis: {
            type: 'category',

            // boundaryGap: false,

            axisLine: {
                onZero: false,
                show: true,

                lineStyle: {
                    color: '#1178C9'
                }
            },
            axisLabel: {
                interval: 0,

                textStyle: {
                    color: '#97B8C9',
                    fontSize: 16

                },
                formatter: function (params) {

                    if (params.length > 4) {
                        var _name = params.substring(0, 4) + '\n' + params.substring(4, params.length);
                        return _name;
                    }
                    return params
                }

            },

            axisLine: {
                show: true,
                lineStyle: {
                    color: '#07274D'
                }
            },
            axisTick: {
                lineStyle: {
                    color: '#1178C9'
                }
            },
            splitLine: {
                lineStyle: {
                    color: '#07274D'
                }
            },
            data: [
                '城市',
                '乡镇'


            ]
        },
        yAxis: [

            {
                type: 'value',
                show: false,
                interval: 0,
                splitLine: {
                    lineStyle: {
                        color: '#07274D'
                    }
                },
                axisLine: {
                    onZero: false,

                    lineStyle: {
                        color: '#07274D'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#1178C9'
                    }
                },
                axisLabel: {
                    textStyle: {
                        color: '#97B8C9',
                        fontSize: 16

                    },

                    formatter: '{value} '
                }
            }
        ],

        series: [{
            name: '药品',
            type: 'bar',
            barWidth: 28,
            itemStyle: {
                normal: {
                    color: "#EB3432"

                }
            },
            data: [
                1,
                22,

            ]

        }, {
            name: '医疗器械',
            type: 'bar',
            barWidth: 28,
            itemStyle: {
                normal: {
                    color: "#0091FF"
                    //  function(value) {
                    //     var coloeList = [
                    //         '#DF31EB',
                    //         '#7630ED',
                    //         '#3157EC',
                    //         '#4FE0FD',
                    //         '#21FB30',
                    //         '#EB3432',
                    //         '#FF8516',
                    //         '#F2E52C'
                    //     ]
                    //     return coloeList[value.dataIndex]
                    //
                    // }
                }
            },
            data: [
                1,
                22,

            ]

        }]
    };

    myChart.setOption(option);

}


function showRightBar1() {
    var myChart = echarts.init(document.getElementById('bar2'))
    var option = {
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b}: {c} ',
            textStyle: {
                fontSize: 18
            }
        },
        grid: {
            top: 30,
            left: '3%',
            right: '4%',
            bottom: '0',
            containLabel: true
        },
        xAxis: {
            show: false,

        },
        yAxis: {
            type: 'category',

            axisLabel: {
                interval: 0,
                show: true,
                textStyle: {
                    color: '#ddd',
                    fontSize: 18
                }
            },
            axisTick: {
                show: false
            },
            data: [
                '集团',
                '分公司',
                '个人独资',
                '个体户',
                '外商',
                '其他'


            ]
        },

        series: [{
                name: '药械企业类型情况',
                type: 'bar',

                itemStyle: {
                    normal: {
                        color: function (value) {
                            var coloeList = [
                                '#DF31EB',
                                '#7630ED',
                                '#3157EC',
                                '#4FE0FD',
                                '#21FB30',
                                '#EB3432',
                                '#FF8516',
                                '#F2E52C',
                                '#FF003F',
                                '#97683F',
                                '#00BF5F'
                            ]
                            return coloeList[value.dataIndex]

                        },
                        textStyle: {
                            fontSize: 18
                        },
                        label: {
                            show: true,
                            position: 'right',
                            fontSize: 18,
                            textStyle: {
                                fontSize: 18,
                            }
                        }
                    }
                },
                data: [
                    13,
                    23,
                    29,
                    10,
                    14,
                    630


                ]
            }

        ]
    }
    myChart.setOption(option)

}